﻿Public Class userDetailsForm
    Dim check As Boolean = False
    Private condition As String
    Private no_room As Integer = 0
    Private rooms As Integer = 0

    Dim checkin As New checkin
    Dim onlineCheckIn As New onlineCheckIn
    Dim checkRooms As New checkRooms

    Public Sub setCond(ByVal cond)
        condition = cond
    End Sub


    Private Sub backBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles backBtn.Click
        Me.Hide()
    End Sub

    Private Sub bookBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles checkInBtn.Click
        no_room = checkRooms.checkRooms()
        Dim arrival As String = checkInForm.checkInDatePicker.Value.ToString()
        Dim departure As String = checkInForm.checkOutDatePicker.Value.ToString()
        If (condition = "online") Then
            If (rooms + 1 < no_room) Then
                rooms += 1
                onlineCheckIn.insert()
                Me.Hide()
            Else
                onlineCheckIn.insert()
                onlineCheckIn.delete()
                Me.Hide()
                roomForm.Hide()
                bookedOnlineForm.Hide()
                mainForm.Show()
            End If
        ElseIf (condition = "checkin") Then
            If (firstNameTxt.Text = "First Name" Or lastNameTxt.Text = "Last Name" Or emailTxt.Text = "") Then
                MessageBox.Show("No empty data is allowed!!")
            ElseIf (IsNumeric(contactTxt.Text) = False Or IsNumeric(creditCardTxt.Text) = False Or IsNumeric(firstNameTxt.Text) = True Or IsNumeric(lastNameTxt.Text) = True Or IsNumeric(emailTxt.Text) = True) Then
                MessageBox.Show("Wrong data format!")
            ElseIf (creditCardTxt.Text.Length <> 10) Then
                MessageBox.Show("Invalid credit card number! Credit number must have exactly 10 characters!")
            ElseIf (contactTxt.Text.Length < 6) Then
                MessageBox.Show("Invalid phone number! Phone number must be at least 6 characters!")
            Else
                checkin.insert()
                Me.Hide()
            End If
        End If
    End Sub

    Private Sub firstNameTxt_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles firstNameTxt.Click
        firstNameTxt.SelectionStart = 0
        firstNameTxt.SelectionLength = firstNameTxt.Text.Length
        If (firstNameTxt.Text = "First Name") Then
            firstNameTxt.Text = ""
        End If
    End Sub

    Private Sub firstNameTxt_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles firstNameTxt.LostFocus
        If (firstNameTxt.Text = "") Then
            firstNameTxt.Text = "First Name"
            firstNameTxt.ForeColor = Color.Gray
        Else
            If (firstNameTxt.Text = "First Name") Then
                firstNameTxt.ForeColor = Color.Gray
            Else
                firstNameTxt.ForeColor = Color.Black
            End If
        End If
    End Sub

    Private Sub lastNameTxt_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lastNameTxt.Click
        lastNameTxt.SelectionStart = 0
        lastNameTxt.SelectionLength = lastNameTxt.Text.Length
        If (lastNameTxt.Text = "Last Name") Then
            lastNameTxt.Text = ""
        End If
    End Sub

    Private Sub lastNameTxt_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles lastNameTxt.LostFocus
        If (lastNameTxt.Text = "") Then
            lastNameTxt.Text = "Last Name"
            firstNameTxt.ForeColor = Color.Gray
        Else
            lastNameTxt.ForeColor = Color.Black
        End If
    End Sub


    Private Sub userDetailsForm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        logoPic.Location = New System.Drawing.Point(((userDetailsPanel.Width / 2) - (logoPic.Width / 2)), 3)
        userDetailsPanel.Location = New System.Drawing.Point(((Me.Width / 2) - (userDetailsPanel.Width / 2)), ((Me.Height / 2) - (userDetailsPanel.Height / 2)))
        If (condition = "online") Then
            nameLbl.Visible = False
            contactLbl.Visible = False
            emailLbl.Visible = False
            credCardLbl.Visible = False
            firstNameTxt.Visible = False
            lastNameTxt.Visible = False
            contactTxt.Visible = False
            emailTxt.Visible = False
            creditCardTxt.Visible = False
        End If
    End Sub

    Private Sub roomNoTxt_Click(sender As System.Object, e As System.EventArgs) Handles roomNoTxt.Click

    End Sub

    Private Sub userDetailsPanel_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles userDetailsPanel.Paint

    End Sub
End Class